package com.leetcode.LC_MED;

public class LC474 {
    public int findMaxForm(String[] strs, int m, int n) {
        // dp[i][j] 表示有i个1和j个0最大集合
        int[][] dp = new int[m + 1][n + 1];
        for (int i = 0; i < strs.length; i++) {
            int zeroNum = 0;
            int oneNum = 0;
            for (char c : strs[i].toCharArray()) {
                if (c == '0') zeroNum++;
                else oneNum++;
            }
            for (int j = m; j >= zeroNum; j--) {
                for (int k = n; k >= oneNum; k--) {
                    dp[j][k] = Math.max(dp[j][k], dp[j - zeroNum][k - oneNum] + 1);
                }
            }
        }
        return dp[m][n];
    }
}
